package cn.shuangbofu.test;

import cn.shuangbofu.test.server.alarm.AlarmEmitter;
import cn.shuangbofu.test.server.dispatcher.TaskDisptacher;
import cn.shuangbofu.test.server.scheduler.GlobalController;
import cn.shuangbofu.test.server.scheduler.event.ServerStartEvent;
import cn.shuangbofu.test.server.scheduler.task.TaskRetryScheduler;
import cn.shuangbofu.test.server.scheduler.task.TaskScheduler;

/**
 * Created by shuangbofu on 2020/7/22 10:51
 */
public class DTServer {
    private static final int DISPATCHER_THREAD_NUM = 2;
    private static final int REJECT_RETRY_INTERVAL = 3;
    private static final int AUTO_RETRY_INTERVAL = 4;

    public static void main(String[] args) {
        // TODO 开启服务
        // NETTY OR AKKA
        TaskDisptacher.INSTANCE.start(DISPATCHER_THREAD_NUM);
        TaskRetryScheduler.INSTANCE.start(REJECT_RETRY_INTERVAL, AUTO_RETRY_INTERVAL);
        // 指标metric

        // 注册所有观察者，
        initAllObserver();
    }

    public static void initAllObserver() {
        GlobalController controller = GlobalController.getInstance();
        controller.register(TaskScheduler.getInstance());
        controller.register(AlarmEmitter.getInstance());

        controller.notify(new ServerStartEvent());
    }
}
